﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：DepartMentInfo
// 文件功能描述：食材类型管理
//
// 
// 创建标识：2012-01-18 jy
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;


namespace Model.WaiGaoQiao
{
    public class Con_GoodsInfo
    {
        /// <summary>
        /// 部门编号
        /// </summary>
        public int Id
        {
            get;
            set;
        }

        /// <summary>
        /// 部门代码
        /// </summary>
        public string GoodsNo
        {
            get;
            set;
        }

        /// <summary>
        /// 食材名称
        /// </summary>
        public string GoodsName
        {
            get;
            set;
        }

        /// <summary>
        /// 单位
        /// </summary>
        public string GoodsUnit
        {
            get;
            set;
        }

        /// <summary>
        /// 上级代码
        /// </summary>
        public int PriorID
        {
            get;
            set;
        }

        public string Type
        {
            get;
            set;
        }

        private DataAccessCon_Goods goodsAccess;
        private int rowcount;
        public int _rowcount
        {
            get { return rowcount; }
        }

        public Con_GoodsInfo()
        {

        }

        public Con_GoodsInfo(bool isgetcount)
        {
            goodsAccess = new DataAccessCon_Goods();
            if (isgetcount)
            {
                rowcount = GetCon_GoodsCount("");
            }
        }

        /// <summary>
        /// 食材类型数量
        /// </summary>
        /// <returns></returns>
        public int GetCon_GoodsCount(string Condition)
        {
            return goodsAccess.GetCon_GoodsCount(Condition);
        }

        /// <summary>
        /// 仓库中的食材数量合计
        /// </summary>
        /// <param name="Condition"></param>
        /// <returns></returns>
        public int GetCon_Goods_StocksCount(string Condition)
        {
            return goodsAccess.GetCon_Goods_StocksCount(Condition);
        }

        /// <summary>
        /// 获取所有食材类型(分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public Con_GoodsInfo GetCon_GoodsById(int Id)
        {
            Con_GoodsInfo comInfo = new Con_GoodsInfo();
            DataSet ds = goodsAccess.GetCon_GoodsById(Id);

            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                DataRow item = ds.Tables[0].Rows[0];

                comInfo = new Con_GoodsInfo()
                {
                    Id = Convert.ToInt32(item[0]),
                    GoodsNo = item[1].ToString(),
                    GoodsName = item[2].ToString(),
                    GoodsUnit = item[3].ToString(),
                    PriorID = Convert.ToInt32(item[4]),
                    Type = item[5].ToString()
                };
            }
            return comInfo;
        }

        /// <summary>
        /// 获取所有食材类型(分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<Con_GoodsInfo> GetAllCon_Goods(string condition)
        {
            IList<Con_GoodsInfo> dmlist = new List<Con_GoodsInfo>();
            Con_GoodsInfo dminfo;
            DataSet ds = goodsAccess.GetAllCon_Goods(condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Con_GoodsInfo();
                dminfo.Id = Convert.ToInt32(item[0]);
                dminfo.GoodsNo = item[1].ToString();
                dminfo.GoodsName = item[2].ToString();
                dminfo.GoodsUnit = item[3].ToString();
                dminfo.PriorID = Convert.ToInt32(item[4]);
                dmlist.Add(dminfo);
            }
            return dmlist;
        }

        /// <summary>
        /// 获取仓库中的食材
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Con_GoodsInfo> GetCon_Goods_StocksList(string condition)
        {
            IList<Con_GoodsInfo> dmlist = new List<Con_GoodsInfo>();
            Con_GoodsInfo dminfo;
            DataSet ds = goodsAccess.GetCon_Goods_StocksList(condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Con_GoodsInfo()
                {
                    Id = Convert.ToInt32(item[0]),
                    GoodsName = item[2].ToString()
                };
                dmlist.Add(dminfo);
            }
            return dmlist;
        }
        /// <summary>
        /// 从库存表中获取主副调食材的库存
        /// </summary>
        /// <param name="Condition"></param>
        /// <returns></returns>
        public IList<Con_GoodsInfo> GetCon_Goods_StocksList1(string Condition)
        {
            IList<Con_GoodsInfo> dmlist = new List<Con_GoodsInfo>();
            Con_GoodsInfo dminfo;
            DataSet ds = goodsAccess.GetCon_Goods_StocksList1(Condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Con_GoodsInfo()
                {
                    GoodsNo = item["GOODSNO"].ToString(),
                    GoodsName = item["GoodsName"].ToString()
                };
                dmlist.Add(dminfo);
            }
            return dmlist;
        }
        /// <summary>
        /// 获取仓库中的零星物品
        /// </summary>
        /// <param name="Condition"></param>
        /// <returns></returns>
        public IList<Con_GoodsInfo> GetCon_Goods_Stocks_SporadicList(string Condition)
        {
            IList<Con_GoodsInfo> dmlist = new List<Con_GoodsInfo>();
            Con_GoodsInfo dminfo;
            DataSet ds = goodsAccess.GetCon_Goods_Stocks_SporadicList(Condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Con_GoodsInfo()
                {
                    Id = Convert.ToInt32(item[0]),
                    GoodsNo = item[1].ToString(),
                    GoodsName = item[2].ToString()
                };
                dmlist.Add(dminfo);
            }
            return dmlist;
        }

        /// <summary>
        /// 获取所有食材类型(分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<Con_GoodsInfo> GetAllCon_Goods(string Condition, int pagesize, int startindex)
        {
            IList<Con_GoodsInfo> dmlist = new List<Con_GoodsInfo>();
            Con_GoodsInfo dminfo;
            DataSet ds = goodsAccess.GetAllCon_Goods(Condition, pagesize, startindex);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Con_GoodsInfo()
                {
                    Id = Convert.ToInt32(item[0]),
                    GoodsNo = item[1].ToString(),
                    GoodsName = item[2].ToString(),
                    GoodsUnit = item[3].ToString(),
                    PriorID = Convert.ToInt32(item[4])
                };
                dmlist.Add(dminfo);
            }
            return dmlist;
        }

        /// <summary>
        /// 保存或修改部门信息
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveCon_Goods(Con_GoodsInfo dminfo)
        {
            object[] dpmpara = new object[] {dminfo.Id, dminfo.GoodsNo,dminfo.GoodsName,dminfo.GoodsUnit,
                                              dminfo.PriorID,dminfo.Type };
            return goodsAccess.SaveCon_Goods(dpmpara);
        }


        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteCon_Goods(string Id)
        {
            return goodsAccess.DeleteCon_Goods(Id);
        }
        /// <summary>
        /// 根据ID获取食材名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetGoodsNameByID(int id)
        {
            return DataAccessCon_Goods.GetGoodsNameByID(id);
        }
        /// <summary>
        /// 是否存在子节点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool IsExistSubNode(int id)
        {
            return goodsAccess.IsExistSubNode(id);
        }
    }
}
